package com.xy.order.service.dto.impl;

import com.ruoyi.common.core.domain.order.dto.OrderTypeDto;
import com.ruoyi.common.core.domain.order.vo.OrderDetailVo;
import com.ruoyi.common.core.domain.order.vo.TakeOrderSkills;
import com.ruoyi.common.core.domain.order.vo.TakeOrdersInfo;
import com.ruoyi.common.core.domain.order.vo.TakeOrdersService;
import com.ruoyi.common.core.domain.user.Address;
import com.ruoyi.common.core.mapper.order.vo.TakeOrdersServiceMapper;
import com.xy.order.service.dto.TakeOrdersService01;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class TakeOrdersService01Impl implements TakeOrdersService01 {

    @Autowired
    private TakeOrdersServiceMapper takeOrdersServiceMapper;

    /**
     * 1. 获取接单服务
     *
     * @return
     */
    @Override
    public List<TakeOrdersService> listServices() {
        return takeOrdersServiceMapper.listServices();
    }

    /**
     * 2. 获取服务规模
     *
     * @param serviceId 服务类型ID
     * @return
     */
    @Override
    public List<OrderDetailVo> selectOrderTypeByServiceId(Long serviceId) {
        return takeOrdersServiceMapper.selectOrderTypeByServiceId(serviceId);
    }

    /**
     * 3. 用户下单
     *
     * @param takeOrdersInfo
     * @return
     */
    @Override
    public int addOrder(TakeOrdersInfo takeOrdersInfo) {
        // 生成订单流水号
        String orderNo = generateOrderNo();
        takeOrdersInfo.setOrderNo(orderNo);
        return takeOrdersServiceMapper.insertTakeOrdersInfo(takeOrdersInfo);
    }

    /**
     * 生成订单流水号
     * 格式：yyyyMMddHHmmss + 4位随机数
     */
    private String generateOrderNo() {
        String timePart = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date());
        int randomPart = (int) ((Math.random() * 9 + 1) * 1000); // 1000-9999
        return timePart + randomPart;
    }

    /**
     * 4. 获取服务技能
     *
     * @param serviceId
     * @return
     */
    @Override
    public List<TakeOrderSkills> selectSkillsByServiceId(Long serviceId) {
        return takeOrdersServiceMapper.selectSkillsByServiceId(serviceId);
    }
}
